<template>
    <h2>修改页面</h2>
<table>
    <tr>
        <td>借款名称</td>
        <td><input type="text" v-model="Info.BM_Name"></td>
    </tr>
    <tr>
        <td>借款年限</td>
        <td><input type="text" v-model="Info.BM_Year"></td>
    </tr>
    <tr>
        <td>借款最高额度</td>
        <td><input type="text" v-model="Info.BM_Money"></td>
    </tr>
    <tr>
        <td>借款介绍</td>
        <td><input type="text" v-model="Info.BM_Info"></td>
    </tr>
    <tr>
        <td>借款利息编号</td>
        <td>
            <select name="" id="" v-model="Info.BMI_Id">
                <option value="0">--请选择--</option>
                <option v-for="i in BMI" :value="i.BMI_Id">{{ i.BMI_Year }}年{{ i.BMI_Interest }}%</option>
            </select>
        </td>
    </tr>
    <tr>
        <td colspan="2"><button @click="Update">修改</button></td>
    </tr>
</table>
</template>
<script setup lang="ts">
import {ref,onMounted} from 'vue'
import { useRouter,useRoute } from 'vue-router';
const router=useRouter()
const route=useRoute()
import axios from 'axios';
const Info =ref(
    {
        BM_Name:'',
        BM_Year:0,
        BM_Money:0,
        BM_Info:'',
        BMI_Id:0,
        BM_Id:route.query.Bid
    }
)
const BMI=ref([
    {
        BMI_Id:0,
        BMI_Year:0,
        BMI_Interest:0
    }
]
)
onMounted(()=>{
    Bind()
    SelectById()
})
const Bind=()=>{
    axios.get('https://localhost:44358/api/Borrow/Bind',

    ).then(res=>{
        BMI.value=res.data
    }).catch(err=>{
        console.log(err);
    })
}
const SelectById=()=>{
    axios.get('https://localhost:44358/api/Borrow/SelectById',
        {
            params:{
                Bid:route.query.Bid
            }
        }
    ).then(res=>{
        Info.value=res.data
    }).catch(err=>{
        console.log(err);
    })
}
const Update=()=>{
    axios.post('https://localhost:44358/api/Borrow/UpdateBorrow',
        {
            BM_Id:route.query.Bid,
            BM_Name:Info.value.BM_Name,
            BM_Year:Info.value.BM_Year,
            BM_Money:Info.value.BM_Money,
            BM_Info:Info.value.BM_Info,
            BMI_Id:Info.value.BMI_Id
        }

    ).then(res=>{
        if(res.data>0){
            alert("修改成功")
            router.push('/ShowBorrow')
        }
    }).catch(err=>{
        console.log(err);
    })
}


</script>